#include "application.h"

#include "view.h"
#include "gamecontroller.h"
#include "model.h"

using namespace spacedefender;

Application::Application()
{
	_exitGame = false;
	_view = 0;
	_controller = 0;
	_model = 0;
	
	_lw = new LogWriter("spacedefender.log");
}

Application::~Application()
{
	
	if(_view)
	{
		delete _view;
		_view = 0;
	}
	
	if(_controller)
	{
		delete _controller;
		_controller = 0;
	}

	if(_model)
	{
		delete _model;
		_model = 0;
	}
	
	if(_lw)
	{
		delete _lw;
		_lw = 0;
	}
}



bool Application::Initialize()
{
	_model = new Model();
	_view = new View(_model);
	_controller = new GameController(_view, _model);
	
	return _model->Initialize() && _view->Initialize() && _controller->SetupInputSystem();
}

void Application::Run()
{
	while(_view->Update())
	{	
		_model->Update();
	}
}
